<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<script type="text/javascript" src="${CONTEXT_PATH}/js/login/business/charge/ChargeConstant.js"></script>
<%--该页为嵌入页面--%>
<s:hidden name="tuition.totalAmount" id="totalAmount"></s:hidden>
<div style="width:100%;" id="indexAddDiv">
	<s:iterator value="indexList" status="s">
		<div class="indexDiv" id="indexDiv<s:property value='id' />">
			<nobr>
			<div style="width:100px; display:inline-block; float:left; line-height:24px; padding:0px 0px 0px 2px;">
				<s:property value="indexName"/>
			</div>
			<s:hidden name="indexGroup" value="%{id}"></s:hidden>
			<s:hidden name="indexNameGroup" value="%{indexName}"></s:hidden>
			￥
			<s:textfield name="amountGroup" id="amountTxt%{id}" cssStyle="width:50px" value="0" onblur="amountCheck('%{id}')"></s:textfield>
			从
			<input type="text" name="dateStartGroup" id="dateStart<s:property value='id' />" style="width:100px" class="WDate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" onblur="checkTotalAmount()" value="<s:property value='today' />" />
			至
			<input type="text" name="dateEndGroup" id="dateEnd<s:property value='id' />" style="width:100px" class="WDate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" onblur="checkTotalAmount()" />
			
			</nobr>
		</div>
	</s:iterator>
	
	<div id="indexAddDiv"></div>
</div>
<br/>
<a href="javascript:addActualIndex()">添加指标</a>

<br>
<table cellpadding="0" cellspacing="0" width="100%">
	<tr>
		<td width="15%" align="left" height="30px">
			
		</td>
		<td width="20%" align="right">
			保教费折扣：
		</td>
		<td width="15%" align="left">
			<s:select name="discount" id="discount" list="discountList" listKey="value" listValue="label" cssStyle="width:100px;" onchange="checkTotalAmount()"></s:select>
		</td>
		<td width="35%" align="right">
			总金额（￥）：
		</td>
		<td width="15%" align="left">
			<div style="display:inline; width:100px;" id="totalAmountDiv" align="left">0</div>
		</td>
	</tr>
</table>

<div id="indexDivTemp" style="display:none;">
	<div class="indexDiv" id="indexDiv#id#">
		<nobr>
		<div style="width:100px; display:inline-block; float:left; line-height:24px; padding:0px 0px 0px 2px;">
			<s:select name="indexGroup" id="indexSel#id#" list="indexList" listKey="id" listValue="indexName" cssStyle="width:120px" onchange="indexSelChange('#id#')"></s:select>
			<s:hidden name="indexNameGroup" id="nameHidd#id#"></s:hidden>
		</div>
		￥
		<s:textfield name="amountGroup" id="amountTxt#id#" cssStyle="width:50px" value="0" onblur="amountCheck('#id#')"></s:textfield>
		从
		<input type="text" name="dateStartGroup" id="dateStart#id#" style="width:100px" class="WDate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" onblur="checkTotalAmount()" value="<s:property value='today' />" />
		至
		<input type="text" name="dateEndGroup" id="dateEnd#id#" style="width:100px" class="WDate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" onblur="checkTotalAmount()" />
		&nbsp;<a href="javascript:clearIndex('#id#')">删除</a>
		</nobr>
	</div>
</div>

<script>
var n = 0;
var handId = 'hand_';
function amountCheck(id)
{
	var amountTxtx = $('#amountTxt' + id);
	if(isNotNull(amountTxtx.val()) && checkFloat(amountTxtx) == false)
	{
		showMsg('金额有误。', function(){amountTxtx.focus();});
		amountTxtx.val('');
		return;
	}
	checkTotalAmount();
}

function computeTotalAmount()
{
	var indexGroup = $(':input[name="indexGroup"]');
	var amountGroup = $('input:text[name="amountGroup"]');
	var dateStartGroup = $('input:text[name="dateStartGroup"]');
	var dateEndGroup = $('input:text[name="dateEndGroup"]');
	var indexNameGroup = $('input:hidden[name="indexNameGroup"]');
	var discount = $('#discount');
	if(!checkInteger(discount) && !checkFloat(discount))
	{
		showMsg('折扣有误，不为浮点型。', function(){discount.focus()});
		return 0;
	}
	var len = indexGroup.length;
	var sum = 0.00;
	for(var i = 0; i < len - 1; i++)
	{
		var amountx = $(amountGroup.get(i));
		var amountFloat = parseFloat(amountx.val(), 10);
		if(amountFloat == 0)
		{
			continue;
		}
		if(!isNotNull(amountx.val()))
		{
			return 0;
		}
		var dateStartx = $(dateStartGroup.get(i));
		var dateEndx = $(dateEndGroup.get(i));
		if(!isNotNull(dateStartx.val()) && amountFloat > 0)
		{
			return 0;
		}
		if(!isNotNull(dateEndx.val()) && amountFloat > 0)
		{
			return 0;
		}
		if(dateStartx.val() > dateEndx.val())
		{
			showMsg('开始日期不能大于结束日期。');
			return 0;
		}
		if(SCHOOLING == $(indexNameGroup.get(i)).val())
		{
			amountFloat = amountFloat * parseFloat(discount.val());
		}
		sum += toNBitFloat(amountFloat, 0);
	}
	sum = toNBitFloat(sum, 0);
	return sum;
}

function checkTotalAmount()
{
	var totalAmount = $('#totalAmount');
	var totalAmountDiv = $('#totalAmountDiv');
	var sum = computeTotalAmount();
	totalAmount.val(sum);
	totalAmountDiv.text(sum);
}

function addActualIndex()
{
	var indexDivTemp = $('#indexDivTemp');
	var html = indexDivTemp.html();
	var newId = handId + n;
	html = html.replaceAll('#id#', newId);
	var indexAddDiv = $('#indexAddDiv');
	indexAddDiv.html(indexAddDiv.html() + html);
	var indexAdd = $('#indexSel' + newId);
	var indexNameAdd = $('#nameHidd' + newId);
	indexNameAdd.val(indexAdd.find('option:selected').text());
	n++;
}

function clearIndex(id)
{
	var indexDivx = $('#indexDiv' + id);
	indexDivx.remove();
	checkTotalAmount();
}

function indexSelChange(id)
{
	var thisIndexSel = $('#indexSel' + id);
	var thisIndexName = $('#nameHidd' + id);
	thisIndexName.val(thisIndexSel.find('option:selected').text());
	checkTotalAmount();
}
</script>